package action;

import java.sql.*;

import connection.DBConnection;



import bean.DemoBean;

public class MessageProcessing {
	public boolean StoreInDB(DemoBean bean)throws SQLException {
		Statement stmt = null;
		Connection currentCon = null;
	    ResultSet rs = null;
		boolean input = false;
		String name = bean.getName();
		String email = bean.getMail();
		String message = bean.getMessage();
		int count = 0;
		String insert ="insert into message (name,email,message) values ('"
            +name
            +"','"
            +email
            +"','"
            +message
            +"');";
		
		try {
		currentCon = DBConnection.getConnection();
        stmt = currentCon.createStatement();
        count =stmt.executeUpdate(insert);      
        if (count != 0){
        	input = true;
        }
        }finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                }
                rs = null;
            }

            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                }
                stmt = null;
            }

            if (currentCon != null) {
                try {
                    currentCon.close();
                } catch (Exception e) {
                }

                currentCon = null;
            }
        }
        return input;
    }
}

